var verify = $("#verify");
var img = verify.find("img")[0];
var input = verify.find("input");

function ref(type) {
    if (type) {
        verify.show();
    }
    img.src = img.src.replace(/t=\d+/, "t=" + Math.floor(Math.random() * 100000));
    input.val("");
}

$(img).click(ref);

//处理登录框回车事件
input.keypress(function (event) {
    if (event.keyCode == 13) {
        $("#login-form").ajaxSubmit({
            success: function (d) {
                if (d.success) {
                    top.location.reload();
                } else {
                    ref(d.verify);
                    alert(d.message);
                }
            },
            error: function () {
                ref(d.verify);
                alert("网络连接异常");
            }
        });
    }
});


//处理登录框回车事件
$("#password").keypress(function (event) {
    if (event.keyCode == 13) {
        $("#login-form").ajaxSubmit({
            success: function (d) {
                if (d.success) {
                    top.location.reload();
                } else {
                    ref(d.verify);
                    alert(d.message);
                }
            },
            error: function () {
                ref(d.verify);
                alert("网络连接异常");
            }
        });
    }
});

//处理登录按钮事件
$("#login-button").click(function () {
    $("#login-form").ajaxSubmit({
        success: function (d) {
            if (d.success) {
                top.location.reload();
            } else {
                ref();
                alert(d.message);
            }
        },
        error: function () {
            ref();
            alert("网络连接异常");
        }
    });
});